import { createRouter, createWebHistory } from 'vue-router'
import demoRouter from './modules/demo'
import Temp404 from '@/views/global/temp/404.vue'
import { useMenuStore } from '@/stores'

const routes = [
  demoRouter,
  { path: '/:pathMatch(.*)*', name: 'NotFound', component: Temp404 },
  {
    name: 'root',
    path: '/',
    component: () => import('@/layout/index.vue'),
    redirect: '/demo/list',
    children: [],
  },
]

const router = createRouter({
  // @ts-ignore
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})
router.beforeEach((to, from, next) => {
  next()
})
export const initRoutes = () => {
  const MenuStore = useMenuStore()
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      MenuStore.initRoutes(MenuStore.mockApi)
      resolve(null)
    }, 2000)
  })
}
export default router
